# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=eventlet
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.40.0
pkgrel=1
pkgdesc="Highly concurrent networking library (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://eventlet.net/'
msys2_repository_url="https://github.com/eventlet/eventlet"
msys2_references=(
  'purl: pkg:pypi/eventlet'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-greenlet"
         "${MINGW_PACKAGE_PREFIX}-python-dnspython"
         "${MINGW_PACKAGE_PREFIX}-python-six")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2: non-blocking PostgreSQL support"
            "${MINGW_PACKAGE_PREFIX}-python-pyopenssl: non-blocking SSL support"
            "${MINGW_PACKAGE_PREFIX}-python-httplib2: non-blocking HTTP support"
            "${MINGW_PACKAGE_PREFIX}-python-pyzmq: non-blocking ZeroMQ support")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-hatchling"
             "${MINGW_PACKAGE_PREFIX}-python-hatch-vcs")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-psycopg2"
              "${MINGW_PACKAGE_PREFIX}-python-nose"
              "${MINGW_PACKAGE_PREFIX}-python-pyopenssl"
              "${MINGW_PACKAGE_PREFIX}-python-httplib2"
              "${MINGW_PACKAGE_PREFIX}-python-mock"
              "${MINGW_PACKAGE_PREFIX}-python-pyzmq")
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz)
sha256sums=('f659d735e06795a26167b666008798c7a203fcd8119b08b84036e41076432ff1')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  sed -r 's|(check_idle_cpu_usage\(.*,) .*\)|\1 0.8\)|g' \
      -i tests/*_test.py
}

build() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/nosetests -sv tests || warning "tests failed"
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
